package com.towker.core.util;

import java.util.*;
import java.sql.*;
import javax.sql.*;
import java.lang.*;

/**
 * 产生一个唯一ID
 * @author 令狐铁民
 * @version 1.0
 */

public class UniqueId
{
    private static long thisId = 0;

    /**
     *根据时间戳产生一个唯一ID,具有防止重复机制
     */
    public synchronized static long genId() throws Exception
    {
        long id = 0;
        do
        {
            Calendar c = Calendar.getInstance();
            id = c.getTimeInMillis();
        }
        while (id == thisId);
        thisId = id;
        return id;
    }
    
    /**
     * 返回GUID
     * @return
     */
    public static String getGuid()
    {
    	UUID uuid = UUID.randomUUID();
    	return uuid.toString();
    }
    

    
}
